
<html>
<head>
<meta http-equiv = "content-Type" content = "text/html" charset = "utf-8">
    <title>방문 요청 확인</title>
     
	 <style type="text/css">
        a{color:black; text-decoration:none; }
		a:link{color:green; text-decoration:none;}
        a:hover{color:black; text-decoration:none; }
        a:visited{color:green; text-decoration:none; }
        a:active{color:black; text-decoration:none; }
    </style>
    <script language="Javascript">

</script>
</head>
	<body>
	<center><h2>방문 요청 확인</h2>

	
<?php>

$connect = mysql_connect("127.0.0.1", "root", "apmsetup"); //DB가 있는 주소(이것은 웹서버로 직접 접속하는 것이기 때문에 루프백 주소를 써인 됨)
if (!$connect) die("Unable to connect to MYSQL: " . mysql_error());

mysql_selectdb("lhu114") or die("Unable to select database : " . mysql_error()); //DB 선택

mysql_query("set names utf8"); //이것 또한 한글(utf8)을 지원하기 위한 것
mysql_query("set names euckr"); //이것 또한 한글(utf8)을 지원하기 위한 것
mysql_query("set session character_set_connection=utf8;");
mysql_query("set session character_set_results=utf8;");
mysql_query("set session character_set_client=utf8;");


 $apiKey = "AIzaSyC0xRoYyS_jR3uQ25h3_Sx4-WNfoWF8aW8";



  $KeyValue = $_REQUEST[KeyValue];
		sendNotification($apiKey,$KeyValue);
    
	
	$message = $_POST['message'];


function sendNotification( $apiKey, $KeyValue )
{   

	$headers = array('Content-Type:application/json; charset=UTF-8', 'Authorization:key=AIzaSyC0xRoYyS_jR3uQ25h3_Sx4-WNfoWF8aW8');

   $connect = mysql_connect("127.0.0.1","root","apmsetup") or die("SQL server에 연결할 수 없습니다."); 
	mysql_selectdb("lhu114") or die("Unable to select database : " . mysql_error()); //DB 선택


	$result3 = mysql_query("SELECT reg_id FROM gcm_table where reg_id='APA91bESOJYA4q7bdkbvmRf_LScTqnYib9S9VVCEs5De84UK62ZpaCA300q32cPOFx3mjyx2cOtEbvvXpADSJZtYK358cJC_hUpv4wM3bVyEHgipj1SpeXL7L0k99dI83_9SZ5mJA1XrJBBZsiXQr01W1PlSmsa-5Q';");
	
     $conidx=0;


$arr   = array();
$arr['data'] = array();
$arr['data']['msg'] = $KeyValue;
$arr['registration_ids'] = array();



while($row = mysql_fetch_array($result3))
  {
	$arr['registration_ids'][$conidx] =  $row['reg_id'] ;
    $conidx++;
  }
	mysql_close($connect);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,    'https://android.googleapis.com/gcm/send');
curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);
curl_setopt($ch, CURLOPT_POST,    true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arr));


$response = curl_exec($ch);

// echo $response;
curl_close($ch);

//return $response;
}
?>

	<br><a href='result.html'>☞ 처음으로</a>
	</center>
    </body>
</html>